import api from "../../api/index.js";
const wxbarcode = require('wxbarcode')
Page({
  data: {
    apiOk: false,
    orderList:[]
  },
  onLoad: function (options) {

  },
  onShow: function () {
    getApp().initLanguage(this)
    wx.setNavigationBarTitle({
      title: this.data.$t.index.PickingUp,
    })
    this.orderList();
  },
  toIndexPage: function () {
    wx.switchTab({
      url: "/pages/index/index"
    });
  },
  async orderList() {
    api.orderPage({
      method: "POST",
      data: {
        orderStatus:2 //待取货
      },
    }).then((res) => {
      this.setData({
        orderList: res.data.records,
        logisticsMap: res.data.logisticsMap,
        goodsMap: res.data.goodsMap,
        apiOk: true
      })
      if (this.data.orderList?.length > 0) {
        wxbarcode.qrcode('qrcode_0', res.data.records[0].id, 400, 400);
      }
    })
  },
  bindchange(e) {
    const index = e.detail.current
    const orderId = this.data.orderList[index].id
    if (!orderId) {
      return
    }
    wxbarcode.qrcode('qrcode_' + index, orderId, 400, 400);
  },
})